var fontSize12 = parseInt(parseInt($('html').css('font-size')) * 0.24);
var recall = getRandom(0, 10, 'int');
var optionCost = {
    backgroundColor: '#373945',
    grid: {
        top: '10px',
        bottom: '0',
        left: '3%',
        right: '40%',
        containLabel: true
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: { // 坐标轴指示器，坐标轴触N发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        },
        position: function(point){
            return [point[0] + 5, point[1] + 5];
        },
        textStyle: {
            fontSize: fontSize12
        },
        formatter: function (a) {
            if (a[0].dataIndex === 0) {
                var value;
                if (param.dataIndex) {
                    value = performanceList[param.dataIndex].curExpenditure;
                } else {
                    value = performanceJson.curExpenditure;
                }
                return '总支出：' + fix2(value/CONST) + '万元<br/>' +
                    '---------------------<br/>' +
                    '人工费用：' + fix2(value * 0.3 / CONST) + '万元<br/>' +
                    '备件费用：' + fix2(value * 0.1 / CONST) + '万元<br/>' +
                    '耗材费用：' + fix2(value * 0.4 / CONST) + '万元<br/>' +
                    '其他费用：' + fix2(value * 0.2 / CONST) + '万元';
            } else {
                var str = '总收入：' + fix2(performanceJson.curIncome/CONST) + '万元<br/>' +
                    '---------------------<br/>';
                for(var i = 0; i < performanceList.length; i++) {
                    str += performanceList[i].name + '：' + fix2(performanceList[i].curIncome/CONST) + '万元<br/>';
                }
                return str;
            }
        }
    },
    xAxis:  {
        show: false,
        type: 'value'
    },
    yAxis: {
        show: true,
        type: 'category',
        axisTick : {show: false},
        axisLabel: {
            show: true,
            fontSize: fontSize12,
            textStyle: {
                color: '#f00'
            }
        },
        axisLine: {
            show: true,
            lineStyle:{
                color:'#fff'
            }
        },
        data: ['支出', '收入']
    },
    series: [{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#62dcdd'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#2cfdaa'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#84fba1'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#c9f96f'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#f7fc57'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#9297fb'
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,10]
    },{
        type: 'bar',
        stack: 'curIncome',
        itemStyle:{
            normal: {
                color: '#4cb8f9',
                barBorderRadius:[0, 200, 200 ,0],
                label: {
                    show: true,
                    position: "right",
                    fontSize: fontSize12,
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function(a) {
                        return a.dataIndex === 1 ? fix2(performanceJson.curIncome/CONST) + '万元' : '';
                    }
                }
            }
        },
        barGap: '-100%',
        barWidth:'50%',
        data: [0,20]
    },{
        type: 'bar',
        stack: 'curExpenditure',
        itemStyle:{
            normal: {
                color: '#8adde1'
            }
        },
        barWidth:'50%',
        data: [120,0]
    },{
        type: 'bar',
        stack: 'curExpenditure',
        itemStyle:{
            normal: {
                color: '#66c3e4'
            }
        },
        barWidth:'50%',
        data: [120,0]
    },{
        type: 'bar',
        stack: 'curExpenditure',
        itemStyle:{
            normal: {
                color: '#fad978'
            }
        },
        barWidth:'50%',
        data: [120,0]
    },{
        type: 'bar',
        stack: 'curExpenditure',
        itemStyle:{
            normal: {
                color:'#efa389',
                barBorderRadius:[0, 200, 200 ,0],
                label: {
                    show: true,
                    position: "right",
                    fontSize: fontSize12,
                    textStyle: {
                        color: '#fff'
                    },
                    formatter: function(a) {
                        var value;
                        if (param.dataIndex) {
                            value = performanceList[param.dataIndex].curExpenditure;
                        } else {
                            value = performanceJson.curExpenditure;
                        }
                        return a.dataIndex === 0 ? fix2(value/CONST) + '万元' : '';
                    }
                }
            }
        },
        barWidth:'50%',
        data: [120,0]
    }]
};

var optionServiceTime = {
    tooltip: {
        trigger: 'item',
        textStyle: {
            fontSize: fontSize12
        },
        formatter: function (param) {
            if (param.seriesIndex === 1) {
                return param.name + '：' + param.value + '次';
            }
            return param.name + '<br/>' +
                '故障次数：' + faultJson[param.dataIndex].curToRepairCounts + '次<br/>' +
                '设备数量：' + faultJson[param.dataIndex].curDeviceCounts + '台<br/>' +
                '故障率：' + fix2(faultJson[param.dataIndex].curAvgFaultRate) + '%<br/>' +
                '同比：' + fix2(faultJson[param.dataIndex].avgFaultRateYoy) + '%<br/>';
        }
    },
    series: [{
        type: 'pie',
        hoverOffset: 3,
        startAngle: 180,
        radius: ['75%', '90%'],
        selectedMode: false,
        selectedOffset: 3,
        label: {
            normal: {
                formatter: function (param) {
                    if (param.dataIndex === 2) {
                        return '累计\n故障次数';
                    } else if (param.dataIndex === 4) {
                        return curToRepairCounts + '次';
                    } else {
                        return '';
                    }
                },
                position: 'center',
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                }
            }
        },
        data: [{
            value: 70,
            name: '平均故障时间',
            itemStyle: {
                normal: {
                    color: '#62dcdd'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#2cfdaa'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#84fba1'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#c9f96f'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#f7fc57'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#9297fb'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#4cb8f9'
                }
            }
        }]
    }, {
        type: 'pie',
        hoverOffset: 2,
        startAngle: 180,
        radius: ['55%', '70%'],
        label: {
            show: false
        },
        data: [{
            value: 70,
            name: '大维修',
            itemStyle: {
                normal: {
                    color: '#fdd951'
                }
            }
        }, {
            value: 127,
            name: '中维修',
            itemStyle: {
                normal: {
                    color: '#5cdbe1'
                }
            }
        }, {
            value: 127,
            name: '小维修',
            itemStyle: {
                normal: {
                    color: '#2e96d3'
                }
            }
        }]
    }]
};

var optionServicePerson = {
    tooltip: {
        trigger: 'item',
        formatter: "{b} : {c} 人",
        textStyle: {
            fontSize: fontSize12
        }
    },
    series: [{
        type: 'pie',
        hoverOffset: 3,
        startAngle: 180,
        radius: ['75%', '90%'],
        selectedMode: false,
        selectedOffset: 3,
        label: {
            normal: {
                formatter: function (param) {
                    if (param.dataIndex === 2) {
                        return '当日服务人次';
                    } else if (param.dataIndex === 4) {
                        return peopleJson.today + '人';
                    } else {
                        return '';
                    }
                },
                position: 'center',
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                }
            }
        },
        data: [{
            value: 70,
            name: '平均故障时间',
            itemStyle: {
                normal: {
                    color: '#62dcdd'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#2cfdaa'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#84fba1'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#c9f96f'
                }
            }
        }, {
            value: 127,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#f7fc57'
                }
            }
        }, {
            value: 0,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#9297fb'
                }
            }
        }, {
            value: 0,
            name: '平均运行时间',
            itemStyle: {
                normal: {
                    color: '#4cb8f9'
                }
            }
        }]
    }]
};

var optionYear = {
    backgroundColor: 'transparent',
    color: ['#00a559', '#ff841a', '#00c0ef', '#f09d0f'],
    tooltip: {
        trigger: 'item',
        textStyle: {
            fontSize: fontSize12
        },
        formatter: function(param) {
            if (param.dataIndex === 1) {
                return '';
            } else {
                if (param.seriesIndex === 0) {
                    return "实际巡检数：" + (YearJson.actualInspectionCounts || 0) + "<br/>" +
                        "计划巡检数：" + (YearJson.planInspectionCounts || 0) + "<br/>" +
                        "巡检完成率: " + fix2(YearJson.inspectionRate) + "%";
                } else if (param.seriesIndex === 1) {
                    return "实际强检数：" + (YearJson.actualCompulsoryCounts || 0) + '<br/>' +
                        "计划强检数：" + (YearJson.planCompulsoryCounts || 0) + "<br/>" +
                        "强检完成率: " + fix2(YearJson.compulsoryRate) + "%";
                } else if (param.seriesIndex === 2) {
                    return "实际保养数：" + (YearJson.actualUpkeepCounts || 0) + "<br/>" +
                        "计划保养数：" + (YearJson.planUpkeepCounts || 0) + "<br/>" +
                        "保养完成率: " + fix2(YearJson.upkeepRate) + "%";
                } else if (param.seriesIndex === 3) {
                    return "已完成次数：" + (YearJson.repairedCounts || 0) + "<br/>" +
                        "报修次数：" + (YearJson.toRepairCounts || 0) + "<br/>" +
                        "维修完成率: " + fix2(YearJson.repairRate) + "%";
                }
            }
        }
    },
    legend: {
        bottom: 10,
        left: "50%",
        data: ['A | 巡检完成率', 'B | 强检完成率', 'C | 保养完成率', 'D | 维修完成率'],
        textStyle: {
            color: '#fff',
            fontSize: fontSize12,
            lineHeight: $('#chartYear').height() * 0.1
        },
        itemGap: 5,
        itemWidth: 0,
        selectedMode: true,
        orient: "vertical"
    },
    series: [{
        name: 'A | 巡检完成率',
        type: 'pie',
        startAngle: 270,
        minAngle: 10,
        clockWise: true, //顺时加载
        hoverAnimation: false, //鼠标移入变大
        center: ['50%', '50%'],
        radius: ['50%', '60%'],
        data: [{
            value: 1,
            itemStyle: {
                normal: {
                    color: '#00a559'
                }
            },
            label: {
                normal: {
                    show: false,
                    color: '#fff',
                    formatter: '{image_icon|}  {word|{c}%}',
                    rich: {
                        image_icon: {
                            color: '#fff',
                            align: 'center',
                            fontSize : fontSize12,
                            backgroundColor: {
                                image: basePath + '/plugins/charts/images/web-icon/monitor.png'
                            }
                        },
                        word: {
                            fontSize : fontSize12,
                            color: '#fff'
                        }
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false,
                    length: 0,
                    length2: 0,
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }
        }, {
            value: 0.33,
            silent: true,
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            },
            label: {
                show: false
            }
        }]
    }, {
        name: 'B | 强检完成率',
        type: 'pie',
        startAngle: 270,
        minAngle: 10,
        clockWise: true, //顺时加载
        hoverAnimation: false, //鼠标移入变大
        center: ['50%', '50%'],
        radius: ['60%', '70%'],
        data: [{
            value: 1,
            itemStyle: {
                normal: {
                    color: '#ff841a'
                }
            },
            label: {
                normal: {
                    show: false,
                    color: '#fff',
                    formatter: '{image_icon|}  {word|{c}%}',
                    rich: {
                        image_icon: {
                            color: '#fff',
                            align: 'center',
                            fontSize : fontSize12,
                            backgroundColor: {
                                image: basePath + '/plugins/charts/images/web-icon/force.png'
                            }
                        },
                        word: {
                            fontSize : fontSize12,
                            color: '#fff'
                        }
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false,
                    length: 0,
                    length2: 0,
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }
        }, {
            value: 0.33,
            silent: true,
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            },
            label: {
                show: false
            }
        }]
    }, {
        name: 'C | 保养完成率',
        type: 'pie',
        startAngle: 270,
        minAngle: 10,
        clockWise: true, //顺时加载
        hoverAnimation: false, //鼠标移入变大
        center: ['50%', '50%'],
        radius: ['70%', '80%'],
        data: [{
            value: 1,
            itemStyle: {
                normal: {
                    color: '#00c0ef'
                }
            },
            label: {
                normal: {
                    show: false,
                    color: '#fff',
                    formatter: '{image_icon|}  {word|{c}%}',
                    rich: {
                        image_icon: {
                            color: '#fff',
                            align: 'center',
                            fontSize : fontSize12,
                            backgroundColor: {
                                image: basePath + '/plugins/charts/images/web-icon/upkeep.png'
                            }
                        },
                        word: {
                            fontSize : fontSize12,
                            color: '#fff'
                        }
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false,
                    length: 0,
                    length2: 0,
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }
        }, {
            value: 0.33,
            silent: true,
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            },
            label: {
                show: false
            }
        }]
    }, {
        name: 'D | 维修完成率',
        type: 'pie',
        startAngle: 270,
        minAngle: 10,
        clockWise: true, // 顺时加载
        hoverAnimation: false, // 鼠标移入变大
        center: ['50%', '50%'],
        radius: ['80%', '90%'],
        data: [{
            value: 1,
            itemStyle: {
                normal: {
                    color: '#f09d0f'
                }
            },
            label: {
                normal: {
                    show: false,
                    color: '#fff',
                    formatter: '{image_icon|}  {word|{c}%}',
                    rich: {
                        image_icon: {
                            color: '#fff',
                            align: 'center',
                            fontSize : fontSize12,
                            backgroundColor: {
                                image: basePath + '/plugins/charts/images/web-icon/repair.png'
                            }
                        },
                        word: {
                            fontSize : fontSize12,
                            color: '#fff'
                        }
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false,
                    length: 0,
                    length2: 0,
                    lineStyle: {
                        color: '#fff'
                    }
                }
            }
        }, {
            value: 0.33,
            silent: true,
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            },
            label: {
                show: false
            }
        }]
    }]
};

var optionMonth = {
    backgroundColor: 'transparent',
    tooltip: {
        textStyle: {
            fontSize: fontSize12
        }
    },
    series: [{
        type: 'pie',
        radius: [0, '100%'],
        legendHoverLink: false,
        hoverAnimation: false,
        silent: true,
        itemStyle: {
            normal: {
                color: '#888890'
            },
            emphasis: {
                color: '#888890'
            }
        },
        label: {show:false},
        data: [100]
    }, {
        type: 'pie',
        radius: ['78%', '81%'],
        legendHoverLink: false,
        hoverAnimation: false,
        itemStyle: {
            normal: {
                color: '#fff'
            },
            emphasis: {
                color: '#fff'
            }
        },
        label: {show:false},
        data: [100]
    }, {
        type: 'pie',
        radius: [0, '90%'],
        label: {show:false},
        data: [{
            value: 85,
            legendHoverLink: true,
            hoverAnimation: false,
            itemStyle: {
                normal: {
                    color: '#fff'
                },
                emphasis: {
                    color: '#fff'
                }
            }
        }, {
            value: 15,
            legendHoverLink: false,
            hoverAnimation: false,
            itemStyle: {
                normal: {
                    color: 'transparent'
                }
            }
        }]
    }]
};

var optionOpenColor = {
    arr: ['#62dcdd', '#2cfdaa', '#84fba1', '#c9f96f', '#f7fc57', '#9297fb', '#4cb8f9'],
    index: 0,
    index2: 6,
    getColor: function (){
        return this.arr[this.index++];
    },
    getColor2: function (){
        return this.arr[this.index2++ % this.arr.length];
    }
};
var optionOpen = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        },
        textStyle: {
            fontSize: fontSize12
        },
        formatter: function (param) {
            return param[0].name + '<br/>' +
                '使用次数：' + fix0(usageJson[param[0].dataIndex].usedCounts) + '次<br/>' +
                '标准使用次数：' + fix0(usageJson[param[0].dataIndex].standardCounts) + '次<br/>' +
                '负荷率：' + fix2(usageJson[param[0].dataIndex].usageRate) + '%';
        }
    },
    grid: {
        top: '3%',
        left: '6%',
        right: '6%',
        bottom: '3%',
        containLabel: true
    },
    yAxis: [{
        type: 'category',
        data: ['超声', '大型影像', '电子仪器', '光学仪器', '检验生化', '内窥镜', '其他'],
        inverse: true,
        axisLine: {
            lineStyle: {
                color: '#fff'
            }
        },
        axisTick: {
            show: false
        },
        axisLabel: {
            show: false,
            textStyle: {
                color: '#fff'
            }
        },
        nameTextStyle: {
            fontSize: fontSize12
        }
    }],
    xAxis: [{
        type: 'value',
        axisLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLabel: {
            show: false
        },
        splitLine: {
            show: false
        }
    }],
    series: [{
        type: 'bar',
        barWidth: '50%',
        barGap: '-100%',
        itemStyle: {
            barBorderRadius: [0, 20, 20, 0]
        },
        z: 11,
        data: [{
            value: 0,
            name: -100,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 0,
            name: 2016101411,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 0,
            name: 2016101405,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 0,
            name: 2016101404,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 0,
            name: 2016101403,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 58,
            name: 2016101403,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }, {
            value: 26,
            name: 2016101403,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: optionOpenColor.getColor()
                    }, {
                        offset: 1,
                        color: optionOpenColor.getColor2()
                    }], false)
                }
            },
            label: {
                show: true,
                position: "inside",
                textStyle: {
                    color: '#fff',
                    fontSize: fontSize12
                },
                formatter: '{c}%'
            }
        }]
    }, {
        type: 'bar',
        barWidth: '50%',
        z: 10,
        itemStyle: {
            barBorderRadius: [0, 20, 20, 0]
        },
        data: [{
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }, {
            value: 100,
            itemStyle: {
                normal: {
                    color: '#c3c4c8',
                    fontSize: fontSize12
                }
            }
        }]
    }]
};